package org.jeecg.modules.manage.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.cmbCloudDirectLink.utils.CMBApi;
import org.jeecg.common.api.dto.BankSetDTO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.LimitSubmit;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.manage.entity.*;
import org.jeecg.modules.manage.service.*;
import org.jeecg.modules.manage.vo.CaishuiUserPage;
import org.jeecg.modules.manage.vo.SigningMemberImportVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

/**
 * @Description: 服务公司[管理]
 * @Author: yfkj
 * @Date: 2023-03-11
 * @Version: V1.0
 */
@Api(tags = "服务公司[管理]")
@RestController
@RequestMapping("/manageApi/caishuiServiceCompany")
@Slf4j
public class MCaishuiServiceCompanyController extends JeecgController<CaishuiServiceCompany, IMCaishuiServiceCompanyService> {

    @Autowired
    private IMCaishuiServiceCompanyService imCaishuiServiceCompanyService;
    @Autowired
    private IMCaishuiMiddleCompanyService imCaishuiMiddleCompanyService;
    @Autowired
    private IMCaishuiCompanySetService imCaishuiCompanySetService;
    @Autowired
    private IMCaishuiRechargeService imCaishuiRechargeService;
    @Autowired
    private IMCaishuiTransactionFlowService imCaishuiTransactionFlowService;
    @Autowired
    private IMCaishuiBusinessService imCaishuiBusinessService;
    @Autowired
    private IMCaishuiBusinessBankService imCaishuiBusinessBankService;
    @Resource
    private ISysBaseAPI iSysBaseAPI;

    /**
     * 分页列表查询
     *
     * @param caishuiServiceCompany
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "服务公司[管理]-分页列表查询", notes = "服务公司[管理]-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<CaishuiServiceCompany>> queryPageList(CaishuiServiceCompany caishuiServiceCompany,
                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                              HttpServletRequest req) {
        QueryWrapper<CaishuiServiceCompany> queryWrapper = QueryGenerator.initQueryWrapper(caishuiServiceCompany, req.getParameterMap());
        Page<CaishuiServiceCompany> page = new Page<CaishuiServiceCompany>(pageNo, pageSize);
        IPage<CaishuiServiceCompany> pageList = imCaishuiServiceCompanyService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 分页列表查询服务公司关联用户列表
     *
     * @param caishuiUserPage
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "服务公司[管理]-分页列表查询服务公司关联用户列表", notes = "服务公司[管理]-分页列表查询服务公司关联用户列表")
    @GetMapping(value = "/userList")
    public Result<IPage<CaishuiUserPage>> queryPageUserList(CaishuiUserPage caishuiUserPage,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                            HttpServletRequest req) {
        QueryWrapper<CaishuiUserPage> queryWrapper = QueryGenerator.initQueryWrapper(caishuiUserPage, req.getParameterMap());
        Page<CaishuiUserPage> page = new Page<CaishuiUserPage>(pageNo, pageSize);
        IPage<CaishuiUserPage> pageList = imCaishuiMiddleCompanyService.pageMultiTable(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 分页列表查询中台用户列表
     *
     * @param caishuiUserPage
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "服务公司[管理]-分页列表查询中台用户列表", notes = "服务公司[管理]-分页列表查询中台用户列表")
    @GetMapping(value = "/subUserList")
    public Result<IPage<CaishuiUserPage>> queryPageSubUserList(CaishuiUserPage caishuiUserPage,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                            HttpServletRequest req) {
        String userId = caishuiUserPage.getUserId();
        caishuiUserPage.setUserId(null);
        QueryWrapper<CaishuiUserPage> queryWrapper = QueryGenerator.initQueryWrapper(caishuiUserPage, req.getParameterMap());
        queryWrapper.eq("del_flag",0);
        queryWrapper.eq("user_type",2);//中台用户
        queryWrapper.ne("middle_opt_auth",0);//不查询系统默认管理员
        Page<CaishuiUserPage> page = new Page<CaishuiUserPage>(pageNo, pageSize);
        IPage<CaishuiUserPage> pageList = imCaishuiMiddleCompanyService.pageSubTable(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param caishuiServiceCompany
     * @return
     */
    @AutoLog(value = "服务公司[管理]-添加")
    @ApiOperation(value = "服务公司[管理]-添加", notes = "服务公司[管理]-添加")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody CaishuiServiceCompany caishuiServiceCompany) {
        /**添加服务公司的同时添加一个租户（服务公司：租户 = 1:1）*/
        //1、添加租户
        Result<?> result = iSysBaseAPI.addTenant(caishuiServiceCompany.getName());
        if (result.isSuccess() && oConvertUtils.isNotEmpty(result.getResult())){
            //2、添加服务公司
            caishuiServiceCompany.setTenantId(Long.valueOf(result.getResult().toString()));
            imCaishuiServiceCompanyService.save(caishuiServiceCompany);
            return Result.OK("添加成功！");
        }else {
            return Result.error("操作失败！");
        }
    }

    /**
     * 服务公司绑定中台用户
     *
     * @param caishuiMiddleCompany
     * @return
     */
    @AutoLog(value = "服务公司[管理]-服务公司绑定中台用户")
    @ApiOperation(value = "服务公司[管理]-服务公司绑定中台用户", notes = "服务公司[管理]-服务公司绑定中台用户")
    @PostMapping(value = "/bindingUser")
    public Result<?> bindingUser(@RequestBody CaishuiMiddleCompany caishuiMiddleCompany) {
        if (oConvertUtils.isEmpty(caishuiMiddleCompany.getTenantId()) || oConvertUtils.listIsEmpty(caishuiMiddleCompany.getUserList())) {
            return Result.error("参数错误！");
        }
        for (CaishuiUserPage userPage : caishuiMiddleCompany.getUserList()) {
            if (userPage.getMiddleOptAuth()!=0) continue;
            //根据租户ID查询服务公司（一个租户只对应一个服务公司）
            CaishuiServiceCompany company = imCaishuiServiceCompanyService.getOne(new LambdaQueryWrapper<CaishuiServiceCompany>()
                    .eq(CaishuiServiceCompany::getTenantId,userPage.getRelTenantIds()));
            if (oConvertUtils.isEmpty(company)) continue;
            //判断是否已存在
            long count = imCaishuiMiddleCompanyService.count(new LambdaQueryWrapper<CaishuiMiddleCompany>()
                    .eq(CaishuiMiddleCompany::getTenantId, caishuiMiddleCompany.getTenantId())
                    .eq(CaishuiMiddleCompany::getUserId, userPage.getId()));
            if (count > 0) continue;
            //添加中台服务公司
            CaishuiMiddleCompany middleCompany = new CaishuiMiddleCompany();
            middleCompany.setTenantId(caishuiMiddleCompany.getTenantId());
            middleCompany.setUserId(userPage.getId());
            middleCompany.setCompanyId(company.getId());
            middleCompany.setCompanyName(company.getName());
            middleCompany.setIsDefault(0);
            imCaishuiMiddleCompanyService.save(middleCompany);
        }
        return Result.OK("绑定成功！");
    }

    /**
     * 移除服务公司中台用户
     *
     * @param id
     * @return
     */
    @AutoLog(value = "服务公司[管理]-移除服务公司中台用户")
    @ApiOperation(value = "服务公司[管理]-移除服务公司中台用户", notes = "服务公司[管理]-移除服务公司中台用户")
    @DeleteMapping(value = "/removeOne")
    public Result<?> removeOne(@RequestParam(name = "id", required = true) String id) {
        imCaishuiMiddleCompanyService.removeById(id);
        return Result.OK("移除成功!");
    }

    /**
     * 编辑
     *
     * @param caishuiServiceCompany
     * @return
     */
    @AutoLog(value = "服务公司[管理]-编辑", dataType = 2)
    @ApiOperation(value = "服务公司[管理]-编辑", notes = "服务公司[管理]-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody CaishuiServiceCompany caishuiServiceCompany) {
        imCaishuiServiceCompanyService.updateById(caishuiServiceCompany);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "服务公司[管理]-通过id删除")
    @ApiOperation(value = "服务公司[管理]-通过id删除", notes = "服务公司[管理]-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        imCaishuiServiceCompanyService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "服务公司[管理]-批量删除")
    @ApiOperation(value = "服务公司[管理]-批量删除", notes = "服务公司[管理]-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.imCaishuiServiceCompanyService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "服务公司[管理]-通过id查询", notes = "服务公司[管理]-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<CaishuiServiceCompany> queryById(@RequestParam(name = "id", required = true) String id) {
        CaishuiServiceCompany caishuiServiceCompany = imCaishuiServiceCompanyService.getById(id);
        if (caishuiServiceCompany == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(caishuiServiceCompany);
    }

    /**
     * 通过服务公司id查询配置
     *
     * @param companyId
     * @return
     */
    @ApiOperation(value = "服务公司[管理]-通过服务公司id查询配置", notes = "服务公司[管理]-通过服务公司id查询配置")
    @GetMapping(value = "/queryByCompanyId")
    public Result<CaishuiCompanySet> queryByCompanyId(@RequestParam(name = "companyId", required = true) String companyId) {
        CaishuiCompanySet caishuiCompanySet = imCaishuiCompanySetService.getOne(new LambdaQueryWrapper<CaishuiCompanySet>()
                .eq(CaishuiCompanySet::getCompanyId, companyId));
        if (oConvertUtils.isNotEmpty(caishuiCompanySet)) {
            //密钥不显示到前端
            caishuiCompanySet.setZsyhBankSm2PubKey(null);
            caishuiCompanySet.setZsyhUserSm2PriKey(null);
            caishuiCompanySet.setZsyhUserSm4Key(null);
        }
        return Result.OK(caishuiCompanySet);
    }

    /**
     * 配置银行秘钥
     *
     * @param caishuiCompanySet
     * @return
     */
    @AutoLog(value = "服务公司[管理]-配置银行秘钥")
    @ApiOperation(value = "服务公司[管理]-配置银行秘钥", notes = "服务公司[管理]-配置银行秘钥")
    @RequestMapping(value = "/set", method = {RequestMethod.PUT, RequestMethod.POST})
//    @RequiresRoles({"admin"})
    public Result<String> set(@RequestBody CaishuiCompanySet caishuiCompanySet) {
    	if(oConvertUtils.isNotEmpty(caishuiCompanySet) && oConvertUtils.isNotEmpty(caishuiCompanySet.getId())){
			imCaishuiCompanySetService.updateById(caishuiCompanySet);
		} else {
            imCaishuiCompanySetService.save(caishuiCompanySet);
		}
        return Result.OK("配置成功!");
    }

    /**
     * 根据开户行编码查询开户行分行
     *
     * @param bankCode
     * @return
     */
    @ApiOperation(value = "服务公司[管理]-通过服务公司id查询配置", notes = "服务公司[管理]-通过服务公司id查询配置")
    @GetMapping(value = "/queryBranchByBankCode")
    public Result<?> queryBranchByBankCode(@RequestParam(name = "bankCode", required = true) String bankCode) {
        List<Map<String,Object>> list = null;
        if ("A03A01".equals(bankCode)) { //招商银行
            list = iSysBaseAPI.queryListBySupCode("A02");
        }
        return Result.OK(list);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param caishuiServiceCompany
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, CaishuiServiceCompany caishuiServiceCompany) {
        return super.exportXls(request, caishuiServiceCompany, CaishuiServiceCompany.class, "服务公司[管理]");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, CaishuiServiceCompany.class);
    }


    /**
     * 查询服务公司历史交易记录
     * 筛选未入库的充值记录
     * @param bankCard   服务公司账号
     * @param beginTime  开始时间
     * @param endTime    结束时间
     * @return
     */
    @ApiOperation(value = "服务公司[管理]-查询服务公司历史交易记录", notes = "服务公司[管理]-查询服务公司历史交易记录")
    @GetMapping(value = "/queryFilterRechargeRecords")
    public Result<List<CaishuiTransactionFlow>> queryFilterRechargeRecords(
            @RequestParam(name = "bankCard", required = true) String bankCard,
            @RequestParam(name = "beginTime", required = true) String beginTime,
            @RequestParam(name = "endTime", required = true) String endTime) {
        List<CaishuiTransactionFlow> list = new ArrayList<>();
        //根据账号查询服务公司设置相关信息
        BankSetDTO bankSetDTO = imCaishuiCompanySetService.queryCompanySet(bankCard);
        if (oConvertUtils.isEmpty(bankSetDTO)) {
            return Result.error("该服务公司还未设置秘钥相关配置！");
        }

        String sDate = beginTime.replaceAll("-","");//开始时间，格式：YYYYMMDD
        String eDate = endTime.replaceAll("-","");//结束时间，格式：YYYYMMDD
        //查询账户下所有记账子单元历史交易记录
        Result<?> result = CMBApi.querySubUnitHistoryTransaction(bankCard, "",sDate,eDate,"", bankSetDTO);
        if(!result.isSuccess()){
            return Result.error(result.getMessage());
        } else if (oConvertUtils.isEmpty(result.getResult())){
            return Result.ok(list);
        }

        //处理交易记录
        JsonArray jsonArray = new GsonBuilder().create().fromJson(result.getResult().toString(), JsonArray.class);
        for (JsonElement jsonElement : jsonArray) {
            try {
                //交易记录数据
                String accnbr = jsonElement.getAsJsonObject().get("accnbr").getAsString();//帐号
                String dmanbr = jsonElement.getAsJsonObject().get("dmanbr").getAsString();//记账子单元编号
                String trxnbr = jsonElement.getAsJsonObject().get("trxnbr").getAsString();//记账流水号
                String trxdir = jsonElement.getAsJsonObject().get("trxdir").getAsString();//交易方向
                if (!"C".equals(trxdir)) {//此处只查询收入的交易记录
                    continue;
                }
                if ("000000".equals(dmanbr)) {//排除：默认记账子单元
                    continue;
                }
                //判断充值记录是否已添加
                long count = imCaishuiRechargeService.count(new LambdaQueryWrapper<CaishuiRecharge>()
                        .eq(CaishuiRecharge::getOrderNo,trxnbr));
                if (count > 0) continue;

                //交易数据
                String dmanam = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("dmanam")) ? "" : jsonElement.getAsJsonObject().get("dmanam").getAsString();
                String ccynbr = jsonElement.getAsJsonObject().get("ccynbr").getAsString();
                double trxamt = jsonElement.getAsJsonObject().get("trxamt").getAsDouble();
                String trxdat = jsonElement.getAsJsonObject().get("trxdat").getAsString();
                String trxtim = jsonElement.getAsJsonObject().get("trxtim").getAsString();
                String rpyacc = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("rpyacc")) ? "" : jsonElement.getAsJsonObject().get("rpyacc").getAsString();
                String rpynam = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("rpynam")) ? "" : jsonElement.getAsJsonObject().get("rpynam").getAsString();
                String trxtxt = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("trxtxt")) ? "" : jsonElement.getAsJsonObject().get("trxtxt").getAsString();
                String narinn = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("narinn")) ? "" : jsonElement.getAsJsonObject().get("narinn").getAsString();
                String mthflg = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("mthflg")) ? "" : jsonElement.getAsJsonObject().get("mthflg").getAsString();
                String balflg = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("balflg")) ? "" : jsonElement.getAsJsonObject().get("balflg").getAsString();
                String onlbal = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("onlbal")) ? "" : jsonElement.getAsJsonObject().get("onlbal").getAsString();
                String rvstag = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("rvstag")) ? "" : jsonElement.getAsJsonObject().get("rvstag").getAsString();
                String autflg = oConvertUtils.isEmpty(jsonElement.getAsJsonObject().get("autflg")) ? "" : jsonElement.getAsJsonObject().get("autflg").getAsString();

                //记账子单元交易流水字段
                CaishuiTransactionFlow transactionFlow = new CaishuiTransactionFlow();
                transactionFlow.setId(UUIDGenerator.generate());
                transactionFlow.setAccnbr(accnbr);
                transactionFlow.setDmanbr(dmanbr);
                transactionFlow.setDmanam(dmanam);
                transactionFlow.setTrxnbr(trxnbr);
                transactionFlow.setCcynbr(ccynbr);
                transactionFlow.setTrxamt(trxamt);
                transactionFlow.setTrxdir(trxdir);
                transactionFlow.setTrxtim(trxdat + trxtim);//交易日期 + 交易时间
                transactionFlow.setRpyacc(rpyacc);
                transactionFlow.setRpynam(rpynam);
                transactionFlow.setTrxtxt(trxtxt);
                transactionFlow.setNarinn(narinn);
                transactionFlow.setMthflg(mthflg);
                transactionFlow.setBalflg(balflg);
                transactionFlow.setOnlbal(onlbal);
                transactionFlow.setRvstag(rvstag);
                transactionFlow.setAutflg(autflg);
                list.add(transactionFlow);//加入集合
            } catch (Exception e){
                log.error("处理交易记录["+jsonElement.getAsJsonObject()+"]失败：" + e.getMessage());
                continue;
            }
        }
        return Result.ok(list);
    }

    /**
     * 添加充值记录处理
     *
     * @param jsonObject
     * @return
     */
    @AutoLog(value = "服务公司[管理]-添加充值记录处理", terminal = 2)
    @PostMapping(value = "/handleRechargeSave")
    @LimitSubmit(key = "manage:company:handleRechargeSave")
    public Result<?> handleRechargeSave(@RequestBody JSONObject jsonObject) throws Exception {
        Object bankCard = jsonObject.get("bankCard");//服务公司账号
        JSONArray jsonArray = jsonObject.getJSONArray("rechargeList");
        if (oConvertUtils.isEmpty(bankCard) || oConvertUtils.listIsEmpty(jsonArray)) {
            return Result.error("参数错误！");
        }

        //公司信息
        CaishuiServiceCompany company = imCaishuiServiceCompanyService.getOne(new LambdaQueryWrapper<CaishuiServiceCompany>()
                .eq(CaishuiServiceCompany::getBankCard, bankCard).eq(CaishuiServiceCompany::getStatus,1));
        if(oConvertUtils.isEmpty(company)){
            return Result.error("服务公司信息错误！");
        }

        for (int i = 0; i < jsonArray.size(); i++) {
            //导入会员数据
            CaishuiTransactionFlow transactionFlow = JSONObject.parseObject(JSON.toJSON(jsonArray.get(i)).toString(), CaishuiTransactionFlow.class);
            if (oConvertUtils.isEmpty(transactionFlow)) continue;
            if (!"C".equals(transactionFlow.getTrxdir())) continue;
            //判断记录是否已添加
            long count = imCaishuiRechargeService.count(new LambdaQueryWrapper<CaishuiRecharge>().eq(CaishuiRecharge::getOrderNo,transactionFlow.getTrxnbr()));
            if (count > 0) continue;
            //根据账号和记账子单元编号查询商户银行信息
            CaishuiBusinessBank businessBank = imCaishuiBusinessBankService.getOne(new LambdaQueryWrapper<CaishuiBusinessBank>()
                    .eq(CaishuiBusinessBank::getType,1).eq(CaishuiBusinessBank::getMainAccount,transactionFlow.getAccnbr())
                    .eq(CaishuiBusinessBank::getSubAccountId,transactionFlow.getDmanbr()));
            if (oConvertUtils.isEmpty(businessBank)) continue;
            //商户信息
            CaishuiBusiness business = imCaishuiBusinessService.getById(businessBank.getBusinessId());
            if (oConvertUtils.isEmpty(business)) continue;

            //新增充值记录
            CaishuiRecharge recharge = new CaishuiRecharge();
            recharge.setCompanyId(businessBank.getServiceCompanyId());
            recharge.setBusinessId(businessBank.getBusinessId());
            recharge.setTenantId(businessBank.getTenantId());
            recharge.setUserId(business.getUserId());
            recharge.setChannelBusinessId(business.getChannelBusinessId());
            recharge.setOrderNo(transactionFlow.getTrxnbr());//记账流水号
            recharge.setMainAccount(transactionFlow.getAccnbr());//主帐号
            recharge.setSubUnitName(transactionFlow.getDmanam());//记账子单元名称
            recharge.setSubUnitCode(transactionFlow.getDmanbr());//记账子单元编号
            recharge.setPaymentAccountName(transactionFlow.getRpynam());//付款户名
            recharge.setPaymentAccount(transactionFlow.getRpyacc());//付款帐号
            recharge.setCollectionAccountName(businessBank.getName());
            recharge.setCollectionAccount(businessBank.getAccount());
            recharge.setAmount(transactionFlow.getTrxamt());//充值金额
            recharge.setRemark(transactionFlow.getTrxtxt());//交易摘要
            recharge.setStatus(1);
            recharge.setCheckStatus(1);
            //充值时间转换
            String date = transactionFlow.getTrxtim();
            if (oConvertUtils.isNotEmpty(date) && date.length() == 14) {
                String date1 = date.substring(0,4) + "-" + date.substring(4,6) + "-" + date.substring(6,8);
                String date2 = date.substring(8,10) + ":" + date.substring(10,12) + ":" + date.substring(12,14);
                recharge.setReceiptTime(DateUtils.sdf.parse(date1 + " " + date2));
            }else {
                recharge.setReceiptTime(new Date());
            }
            imCaishuiRechargeService.save(recharge);
        }

        return Result.OK("操作成功！");
    }

}
